package com.question.utils;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;


public class MyUtils {
	/**
	 * 填充空格
	 */
	public static String fillSpace(String str, Integer count) {
		int oldLength= str.length();
		while(oldLength+count != str.length()) {
			str = " " +str;
		}
		return str;
	}
	/**
	 * 时间格式
	 * @param date
	 * @return
	 */
	public static String date(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(date);
	}
	/**
	 * 读取.properties文件
	 * @param filename 不带扩展名
	 * @param key 
	 * @return
	 */
	public static String readPropertie(String filename,String key) {
		ResourceBundle bundle = ResourceBundle.getBundle(filename);
		try {
			return new String(bundle.getString(key).trim().getBytes("ISO-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static String readMain(String key) {
		return readPropertie("main",key);
	}
	public static String readPrompt(String key) {
		return readPropertie(readMain("prompt"),key);
	}
}
